﻿using System;

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace Sucdri.Infrastructure.Core.Cache
{
   public static class CacheHelper
   {
      private static readonly ICacheManager Cache = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>();

      public static T GetItem<T>(string key)
      {
         return (T)Cache.GetData(key);
      }

      public static void PutItem(string key,object item)
      {
         if(string.IsNullOrEmpty(key))
            throw new ArgumentNullException("key");
         if(null==item)
            throw new ArgumentNullException("item");
         if (Exists(key))
            throw new ArgumentException("Key exists","key");
         Cache.Add(key,item);
      }

      public static void RemoveItem(string key)
      {
         Cache.Remove(key);
      }

      public static void Flush()
      {
         Cache.Flush();
      }

      public static bool Exists(string key)
      {
         return Cache.Contains(key);
      }

      public static int Count()
      {
         return Cache.Count;
      }

   }
}
